package com.lqk.observer;

/**
 * @author lqk
 * @date 2021/12/10 10:30
 *
 * 核心类：
 *  1. 包含最新的天气情况信息
 *  2. 含有 CurrentConditions 对象
 *  3. 当数据有更新时，就主动的调用 CurrentConditions 对象的 update 方法（含display），这样接入方就看到最新的数据
 */
public class WeatherData {
    private float temperatrue;
    private float pressure;
    private float humidity;
    private CurrentConditions currentConditions;

    public WeatherData(CurrentConditions currentConditions) {
        this.currentConditions = currentConditions;
    }

    public float getTemperature() {
        return temperatrue;
    }

    public float getPressure() {
        return pressure;
    }

    public float getHumidity() {
        return humidity;
    }

    public void dataChange() {
        currentConditions.update(getTemperature(), getPressure(), getHumidity());
    }

    // 当数据有更新时，就调用 setData
    public void setData(float temperature, float pressure, float humidity) {
        this.temperatrue = temperature;
        this.pressure = pressure;
        this.humidity = humidity;
        dataChange();
    }
}
